<template>
	<view class="content">
		<view class="content_top">
			<image class="content_top_banner" mode="aspectFill" src="/static/image/banner.png"></image>
			<view class="content_top_box">
				<view class="content_top_box_qr" @click="showQr">
					<image src="/static/image/mpm.png"></image>
					<view class="text">名片码</view>
				</view>
				<view class="content_top_box_user" v-if="userheaderimageurl" @click="link('/comm/card/card?userid='+userid)">
					<image :src="userheaderimageurl"></image>
					<view class="name">{{lxr}}</view>
				</view>
				<view class="content_top_box_user" v-else  @click="link('/user/login/login')">
					<image src="/static/image/tx.png"></image>
					<view class="name">{{lxr}}</view>
				</view>
			</view>
		</view>
		<view class="content_txl" v-if="mytxl.length!=0">
			<!-- <view class="addTxl">
				<view class="box" @click="link('/comm/create/create')">
					<image src="/static/image/jia.png"></image>
					<view class="text">创建通讯录</view>
				</view>
			</view> -->
			<scroll-view class="content_txl_box" :scroll-x="true">
				<view class="list" v-for="(v,k) in mytxl" :key="k" @click="link('/comm/txlindex/txlindex?id='+v.txlid)">
					<view class="box">
						<view class="name overflow2">{{v.txlname}}</view>
						<view class="sum">{{v.inherecount}}人已加入</view>
					</view>
				</view>
			</scroll-view>
		</view>
		<view class="content_hui" v-if="notmytxl.length!=0">
			<view class="content_hui_title">
				<view class="title">
					你可能感兴趣
				</view>
				<view class="break" @click="getIndex">
					<image src="/static/image/sx.png"></image>
					<text>换一批</text>
				</view>
			</view>
			<view class="content_hui_box">
				<view class="list" v-for="(v,k) in notmytxl" :key="k" @click="link('/comm/txlindex/txlindex?id='+v.txlid)">
					<image class="img" :src="v.txlicon"></image>
					<view class="right">
						<view class="title overflow1">{{v.txlname}}</view>
						<view class="news">
							<view class="text">{{v.lxr}}</view>
							<view class="text">
								<image src="/static/image/renshu.png"></image>
								<text>{{v.inherecount}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="content_ad">
			<image :src="indexadbottom.imgpath" @click="link(indexadbottom.linkurl)" mode="widthFix"></image>
		</view>
		<card ref="cardDome" :userid="userid"></card>
	</view>
</template>
<!-- 自适应大屏插件 v-scale-screen -->
<script setup>
	import card from '@/components/card/card.vue'
	import {
		ref
	} from 'vue'
	import {
		homeApi
	} from "@/api/index"
	import {
		onLoad,
		onShow
	} from '@dcloudio/uni-app'
	import {link} from '@/utils/utils.js'
	
	const cardDome = ref(null)
	const showQr = ()=>{
		cardDome.value.show()
	}
	
	onShow(()=>{
		if (uni.getStorageSync("token")) {
			getUserinfo()
		}else{
			lxr.value = '请登录'
		}
		PageNo.value = 1
		getIndex()
	})
	const lxr = ref('')
	const userheaderimageurl = ref('')
	const userid = ref('')
	const getUserinfo = async()=>{
		let data = {
			do:'userinfo',
		}
		let res = await homeApi.publicGet(data)
		for (let i = 0; i < res.columns.length; i++) {
			if (res.columns[i].name == 'userinfo') {
				lxr.value = res.columns[i].lxr?res.columns[i].lxr:''
				userheaderimageurl.value = res.columns[i].userheaderimageurl?res.columns[i].userheaderimageurl:''
				userid.value =  res.columns[i].id?res.columns[i].id:''
			}
		}
	}
	
	const mytxl = ref([])
	const notmytxl = ref([])
	const indexadbottom = ref({})
	const PageNo = ref(1)
	const PageSize = ref(3)
	const PageCount = ref(0)
	const isGet = ref(true)
	const getIndex = async()=>{
		let data = {
			do:'pageindex',
			PageNo:PageNo.value,
			PageSize:PageSize.value
		}
		let res = await homeApi.publicGet(data)
		let list1 = []
		let list2 = []
		for (let i = 0; i < res.columns.length; i++) {
			if (res.columns[i].name == 'mytxl') {
				list1 = res.columns[i].items?res.columns[i].items:[]
			}
			if (res.columns[i].name == 'notmytxl') {
				notmytxl.value = res.columns[i].items?res.columns[i].items:[]
				PageCount.value = res.columns[i].PageCount
			}
			if (res.columns[i].name == 'indexadbottom') {
				list2 = res.columns[i].items?res.columns[i].items:[]
			}
		}
		if(isGet.value){
			mytxl.value = list1
			indexadbottom.value = list2[0]
			isGet.value = false
		}
		if(PageCount.value == PageNo.value){
			PageNo.value=0
		}
		PageNo.value++
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100%;
		height: 100%;
		&_top{
			width: 100%;
			height: 23vh;
			position: relative;
			&_banner{
				position: absolute;
				left: 0;
				top: 0;
				width: 100%;
				height: 20vh;
			}
			&_box{
				position: absolute;
				left: 0;
				top: 0;
				width: calc(100% - 60rpx);
				padding-left: 30rpx;
				padding-right: 30rpx;
				height: 21vh;
				&_qr{
					width: 100%;
					display: flex;
					justify-content:flex-end;
					align-items: center;
					padding-top: 30rpx;
					image{
						width: 50rpx;
						height: 50rpx;
					}
					.text{
						color: #fff;
						font-size: 30rpx;
						margin-left: 10rpx;
					}
				}
				&_user{
					width: calc(100% - 60rpx);
					height: calc(23vh - 170rpx);
					background: #fff;
					border-radius: 15px;
					margin-top: 30rpx;
					box-shadow: 1px 3px 10px rgba(191,203,217,.3);
					padding: 30rpx;
					display: flex;
					align-items: center;
					image{
						width: calc(23vh - 170rpx);
						height: calc(23vh - 170rpx);
						border-radius: 100%;
					}
					.name{
						margin-left: 30rpx;
						font-weight: bold;
						font-size: 38rpx;
					}
				}
			}
		}
		&_txl{
			width: calc(100% - 60rpx);
			padding-left: 30rpx;
			padding-right: 30rpx;
			height: 200rpx;
			margin-top: 40rpx;
			display: flex;
			.addTxl{
				display: inline-block;
				background: linear-gradient(120deg, #ff7022, #f31801);
				height: 200rpx;
				width: 180rpx;
				border-radius: 12px;
				.box{
					width: 100%;
					height: 100%;
					display: flex;
					align-items: center;
					justify-content: center;
					flex-direction: column;
					image{
						width: 80rpx;
						height: 80rpx;
						display: flex;
						margin: 0 auto;
					}
					.text{
						color: #fff;
						font-size: 28rpx;
						width: 100%;
						text-align: center;
						margin-top: 20rpx;
					}
				}
			}
			&_box{
				width: 100%;
				height: 200rpx;
				white-space: nowrap;
				.list{
					display: inline-block;
					height: 200rpx;
					margin-left: 30rpx;
					width: 280rpx;
					background: linear-gradient(120deg, #fff, #fbeded);
					border-radius: 12px;
					.box{
						padding: 20rpx;
						width: calc(100% - 40rpx);
						height: calc(100% - 40rpx);
						display: flex;
						justify-content: space-between;
						flex-direction: column;
						font-size: 28rpx;
						.name{
							font-weight: bold;
							white-space: pre-wrap;
						}
					}
				}
				.list:nth-child(1){
					margin-left: 0;
				}
			}
		}
		&_hui{
			width: calc(100% - 60rpx);
			padding-left: 30rpx;
			padding-right: 30rpx;
			margin-top: 40rpx;
			&_title{
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;
				.title{
					font-size: 34rpx;
					font-weight: bold;
				}
				.break{
					display: flex;
					align-items: center;
					image{
						width: 34rpx;
						height: 34rpx;
					}
					text{
						font-size: 26rpx;
						margin-left: 10rpx;
					}
				}
			}
			&_box{
				width: 100%;
				display: flex;
				flex-direction: column;
				.list{
					width: 100%;
					padding-top: 30rpx;
					padding-bottom: 30rpx;
					display: flex;
					border-bottom: 1px solid #ebecf4;
					justify-content: space-between;
					.img{
						width: 160rpx;
						height: 160rpx;
						border-radius: 8px;
					}
					.right{
						width: calc(100% - 170rpx);
						height: 160rpx;
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						.title{
							font-size: 32rpx;
						}
						.news{
							width: 100%;
							display: flex;
							justify-content: space-between;
							align-items: center;
							font-size: 28rpx;
							color: #666;
							.text{
								display: flex;
								align-items: center;
								justify-content: center;
								image{
									width: 40rpx;
									height: 40rpx;
								}
								text{
									margin-left: 10rpx;
								}
							}
							
						}
					}
				}
			}
		}
		&_ad{
			width: calc(100% - 60rpx);
			padding: 30rpx;
			image{
				width: 100%;
				border-radius: 8px;
			}
		}
	}
</style>